home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 4 / Precision Software Applications Silver Collection Volume 4 (1993).iso / stats / chadyn.exe / YCOM.C < prev    next >
Text File  |  1988-12-13  |  9KB  |  357 lines

  1. /******************************  YCOM.C ***********************************/
  2. /*********************(C) 1986,7,8 by JAMES A. YORKE ************************/
  3.  
  4.  
  5.  
  6. /**********************    Routines in YCASES.c  **************************
  7. some routines in file:
  8.  
  9. select_item(CodeName)
  10. GetCommandAndImplement(CodeName)
  11. implementCommand(CodeName)
  12. Entervalue(val, flag)  gets value from keyboard and returns it as function value
  13. EnterScale(pointer1,pointer2)
  14. abortEnter()
  15. ret_erase_line(i) gives i copies of return(plus line feed) + erase_line() 
  16. MaybeNewLine()
  17. toggle(flag) prints " ON\n" or " OFF\n" 
  18. ***************************************************************************/
  19.  
  20. #include "yinclud.h"
  21. /*#define DEBUG*/
  22. static char    *NotToBeSet =
  23.                 "\nThis variable should not be set for this process\n\n";
  24. static int      counter = 0;
  25.  
  26. /* The main menu is run by this function; it uses fscanf for input:
  27.  * enter a code like XS so you can then change the x scale using this
  28.  * routine; the changes can be either entered from the keyboard(when input
  29.  * == StInput) or from a file whose name was entered on the command line,
  30.  * that is the line used to tell the computer to run this program; in that
  31.  * case input is the pointer to that file.
  32.  */
  33. select_items(CodeName)
  34. char    *CodeName;
  35. {
  36.     level = SETPARAM;
  37.     scr_clr();        /* in desmets pcio.a */
  38.     scr_rowcol(0, 0);
  39.  
  40.     if(coloncommand == NO && input == StInput)
  41.         MainMenu();
  42.  
  43.     while(level == SETPARAM) {
  44.         if(coloncommand == NO && input == StInput) {
  45.             erase_line();
  46.             PRINT
  47.                 "Enter  *(for HELP)  or MM(for repeat of MainMenu) or other Menu item: \n");
  48.             erase_line();
  49.         }
  50.         GetCommandAndImplement(CodeName);
  51.     }
  52. }
  53.  
  54. GetCommandAndImplement(CodeName)
  55. char    *CodeName;
  56. {
  57.     if(GetCommand(CodeName) == 0)
  58.         return;
  59.     if(level >= PROCESS && printer > 0) {
  60.         scr_rowcol(0, 0);
  61.         erase_line();
  62.         ret_erase_line(4);
  63.     }
  64. #ifdef DEBUG
  65.     fprintf(stderr, "implementCommand(%s)\n", CodeName);
  66.     pause(1.0);
  67. #endif
  68.     implementCommand(CodeName);
  69. }
  70.  
  71. implementCommand(CodeName) 
  72. char    *CodeName;
  73. {
  74.     int     plot(), iterate_map();/* needed for pointers */
  75.     int     connect();    /* needed for pointers */
  76.  
  77.     TEST("+") {
  78.         counter++;
  79.         if(counter > 12)
  80.             counter = 0;
  81.  
  82.         if(counter == 0)
  83.             MainMenu();
  84.         if(counter == 1)
  85.             menuV();
  86.         if(counter == 2) {
  87.             if(level == SETPARAM)
  88.                 scr_clr();/* in desmets pcio.a */
  89.             scr_rowcol(0, 0);
  90.             PRINT
  91.                 "         MENU OF KEYBOARD INTERRUPTS --FOR USE WHILE PLOTTING    \n");
  92.             getText("yintrpt.doc", "keys\n");
  93.         }
  94.         if(counter == 3)
  95.             menuP();/* parameters */
  96.         if(counter == 4)
  97.             menuY();
  98.         if(counter == 5)
  99.             DEMenu();/* parameters */
  100.         if(counter == 6)
  101.             diskMenu();
  102.         if(counter == 7)
  103.             BasinMenu();
  104.         if(counter == 8)
  105.             StraddleMenu();
  106.         if(counter == 9)
  107.             NewtonMenu();
  108.         if(counter == 10)
  109.             ManifoldMenu();/* "u" */
  110.         if(counter == 11)
  111.             ColorMenu();    /* command "cm"; in YSCREEN.C */
  112.         if(counter == 12)
  113.             bifMenu();
  114.         return;
  115.     }
  116.     if(MMCommands(CodeName) == 1)
  117.         return;
  118.     if(UndocumentedCommands(CodeName) == 1)
  119.         return;
  120.     if(DECommands(CodeName) == 1)
  121.         return;
  122.     if(VCommands(CodeName) == 1)    /* various and sundry */
  123.         return;
  124.     if(parameters(CodeName) == 1)
  125.         return;
  126.     if(Ycommands(CodeName) == 1)
  127.         return;
  128.     if(caseBs(CodeName) == 1)
  129.         return;
  130.     if(caseDs(CodeName) == 1)
  131.         return;
  132.     if(caseNs(CodeName) == 1)
  133.         return;
  134.     if(caseColor(CodeName) == 1)    /* in YSCREEN.C */
  135.         return;
  136.     if(caseUs(CodeName) == 1)
  137.         return;
  138.     if(bifCommands(CodeName) == 1)
  139.         return;
  140.  
  141.     PRINT
  142.         "\n  * * * * ******** %s: Not a Parameter Menu Item ******** * * * * \n\n"
  143.         ,CodeName);
  144. }
  145.  
  146. /* ENTERVALUE - enter a value from the keyboard.  The current value
  147.  * is passed as the function argument.  When SETIT is nonzero, the value is
  148.  * obtained unconditionally.  Otherwise, if SETIT is zero, and the value is
  149.  * the magic number and we're not supposed to set the value, then an error 
  150.  * message is printed and the function returns the original value.
  151.  * Otherwise, the value is obtained from the keyboard.  The user has the option
  152.  * of aborting the input, which leaves the current value unchanged.
  153.  */
  154. double Entervalue(val, setit)
  155. double    val;
  156. int    setit;
  157. {
  158.     double    newval;
  159.  
  160.     /* can read this variable if initializerFlag == YES */
  161.  
  162.     if(!setit && val == -9999.0 && initializerFlag == NO)
  163.     {
  164.         PRINT NotToBeSet);
  165.         return(val);
  166.     }
  167. /*        SCREEN      means (SCREEN_MENU || SCREEN_PROCESS)
  168.       SCREEN_MENU means (level <=2 && coloncommand == NO && input==StInput)
  169.           SCREEN_PROCESS means    (level >= PROCESS && printer > 0 )
  170. */
  171.     if(SCREEN)
  172.     {
  173.         if (level > 2)
  174.             scr_rowcol(0,0);
  175.         erase_line();
  176.         PRINT
  177. "Current value: %.12g.  Enter value (and then 'Enter'):", val);
  178.         MaybeNewLine();
  179.     }
  180. #ifdef X11
  181.     fflush(printWhere());
  182.     if(input == StInput && sscanf(xwfgets(),"%lf",&newval) == 1
  183.            || input != StInput && fscanf(input, "%lf", &newval) == 1) {
  184. #else
  185.     if(abortEnter() != YES && fscanf(input, "%lf", &newval) == 1){
  186. #endif
  187.         val = newval;
  188.         if(SCREEN) 
  189.         {    erase_line();
  190.             PRINT "New value: %.14g", val);
  191.             ret_erase_line(1);
  192.         }
  193.     } else if(SCREEN)  {
  194.         erase_line();
  195.         PRINT "*** Value unchanged *** \n\n");
  196.     }
  197.     return(val);
  198. }
  199.  
  200. Enter4Int(pointer1, pointer2, pointer3, pointer4)
  201. int    *pointer1,
  202.        *pointer2,
  203.        *pointer3,
  204.        *pointer4;
  205. {
  206.     int    newval[4];
  207.  
  208.     if(SCREEN) {
  209.         erase_line();
  210.         PRINT
  211.             "Current values: %d %d %d %d.     Enter 4 integers (and then 'Enter'):"
  212.             ,*pointer1, *pointer2, *pointer3, *pointer4);
  213.         MaybeNewLine();
  214.     }
  215. #ifdef X11
  216.     if(input == StInput && sscanf(xwfgets(), "%d %d %d %d",
  217.        newval, &newval[1], &newval[2], &newval[3]) == 4
  218.        || input != StInput && fscanf(input, "%d %d %d %d",
  219.        newval, &newval[1], &newval[2], &newval[3]) == 4)  {
  220.         *pointer1 = newval[0];
  221.         *pointer2 = newval[1];
  222.         *pointer3 = newval[2];
  223.         *pointer4 = newval[3];
  224. #else
  225.     if(abortEnter() == YES)
  226.         return;
  227.     if(fscanf(input, "%d %d %d %d", newval, newval + 1, newval + 2,
  228.        newval + 3) == 4)  {
  229.         *pointer1 = newval[0];
  230.         *pointer2 = newval[1];
  231.         *pointer3 = newval[2];
  232.         *pointer4 = newval[3];
  233. #endif
  234.         if(SCREEN) {
  235.             erase_line();
  236.             PRINT "New values: %d %d %d %d\n",
  237.                 newval[0], newval[1], newval[2], newval[3]);
  238.             ret_erase_line(2);
  239.         }
  240.     } else if(SCREEN)  {
  241.         erase_line();
  242.         PRINT "*** Values unchanged *** \n");
  243.         ret_erase_line(2);
  244.     }
  245.     return;
  246. }
  247.  
  248. #ifndef X11
  249. int     abortEnter() {        /* for terminating a command without changing
  250.                    values; specifically: checks to see if input
  251.                    is '\n'; if so it aborts; otherwise is puts
  252.                    the character back in the stream "input"; it
  253.                    discards any leading spaces */
  254. /*    char chr;
  255.      */ int         ch;
  256.  
  257. /*        SCREEN      means (SCREEN_MENU || SCREEN_PROCESS)
  258.       SCREEN_MENU means (level <=2 && coloncommand == NO && input==StInput)
  259.           SCREEN_PROCESS means    (level >= PROCESS && printer > 0 )
  260. */
  261.     if (SCREEN_MENU || level >= PROCESS)
  262.     {
  263.     ch = getc(input);
  264.     if(ch == ' ' || ch == '\n') {
  265.                 /* there is probably a return still in the
  266.                    pipeline from entering the command so this
  267.                    one should not cause an abort */
  268.         ch = getc(input);
  269.     }
  270.     while(ch == ' ' || ch == '\n') {
  271.         if(ch == '\n') {
  272.             PRINT "\n");
  273.             return(YES);
  274.         }
  275.         ch = getc(input);
  276.     }
  277.     ungetc(ch, input);
  278.     }
  279.     return(NO);
  280. }
  281. #endif    /* X11 */
  282.  
  283.  
  284. MaybeNewLine() 
  285. {
  286.     if(level >= PROCESS)
  287.         ret_erase_line(1);
  288. }
  289.  
  290. EnterScale(pointer1, pointer2)
  291. double *pointer1,
  292.        *pointer2;
  293. {
  294.     double    newval[2];
  295.  
  296.     if(SCREEN) {
  297.         PRINT
  298.             "Current scale runs from %.14g to %.14g\n", *pointer1, *pointer2);
  299.         PRINT
  300.             "Enter 2 numbers separated by a space, no comma, then 'return'\n");
  301.         erase_line();
  302.     }
  303. #ifdef X11
  304.     if(input == StInput && sscanf(xwfgets(), "%lf %lf",
  305.        newval, &newval[1]) == 2 || input != StInput 
  306.        && fscanf(input, "%lf %lf", newval, &newval[1]) == 2)  {
  307. #else
  308.     if(abortEnter() != YES && fscanf(input, "%lf %lf", newval, &newval[1])
  309.        == 2)  {
  310. #endif
  311.         *pointer1 = newval[0];
  312.         *pointer2 = newval[1];
  313.         if(SCREEN)
  314.             PRINT "New scale runs from %.14g to %.14g\n",
  315.                 newval[0], newval[1]);
  316.         if(newval[0] == newval[1]) {
  317.             erase_line();
  318.             PRINT "WARNING:NEW VALUES ARE EQUAL; THEY MUST BE RESET");
  319.             ret_erase_line(2);
  320.         }
  321.     } else if(SCREEN)  {
  322.         PRINT "*** Values unchanged\n");
  323.     }
  324.     return;
  325. }
  326.  
  327.  
  328.  
  329. toggle(flag)            /* prints " ON\n" or " OFF\n" */
  330. int     flag;
  331. {
  332.     if(flag == ON)
  333.         PRINT " ON \n");
  334.     else if(flag == OFF)
  335.         PRINT " OFF \n");
  336.     else
  337.         PRINT "%d    \n", flag);
  338. }
  339. incrementD(p, CodeName)
  340. double *p;
  341. char    *CodeName;
  342. {
  343.     if(*p == -9999.&& initializerFlag == NO) {
  344.                 /* can read this variable if initializerFlag ==
  345.                    YES */
  346.         PRINT "This variable is not set and cannot be incremented.\n");
  347.         return;
  348.     }
  349.     pIncrement = p;
  350.     if(SCREEN) {
  351.         erase_line();
  352.         PRINT
  353.            "%s = %g will be incremented by interrupts +/- by RS=%g\n",
  354.             CodeName, *pIncrement, rho_step);
  355.     }
  356. }
  357.